package com.example.neusoftfood_828lhl.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.example.neusoftfood_828lhl.R;
import com.example.neusoftfood_828lhl.adapter.ShopAdapter;
import com.example.neusoftfood_828lhl.bean.ShopBean;
import com.example.neusoftfood_828lhl.listener.RetrofitListener;
import com.example.neusoftfood_828lhl.model.ShopModel;

import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends BaseFragment implements RetrofitListener<List<ShopBean>> {
    private RecyclerView recyclerView;
    private ShopAdapter adapter;
    private List<ShopBean> mDataList;
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle
            savedInstanceState) {
        return inflater.inflate(R.layout.homefragment,container,false);
    }
    public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        initViews(view);
        initData();

    }
    void initViews(View view) {
        recyclerView =  view.findViewById(R.id.home);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        recyclerView.setLayoutManager(new LinearLayoutManager(context));
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        mDataList = getData();
        recyclerView.setAdapter(new ShopAdapter(context,mDataList,R.layout.item));
    }
    void initData() {
        ShopModel shopModel = new ShopModel();
        shopModel.getAllShop(this);
    }
    @Override
    public void onSuccess(List<ShopBean> shops, int flag) {
        adapter = new ShopAdapter(getActivity(),shops,R.layout.item);
        recyclerView.setAdapter(adapter);
    }
    @Override
    public void onFail() {

    }
    private List<ShopBean> getData(){
        List<ShopBean> list = new ArrayList();
        ShopBean shop=new ShopBean();
        shop.setShopname("满口香川菜");
        shop.setAddress("东软食堂三期");
        shop.setPic(R.drawable.ic_launcher_background +"");
        shop.setLevel(5);
        list.add(shop);
        shop=new ShopBean();
        shop.setShopname("东北一家人");
        shop.setAddress("东软食堂三期");
        shop.setPic(R.drawable.ic_launcher_background+"");
        shop.setLevel(2);
        list.add(shop);
        shop=new ShopBean();
        shop.setShopname("姐妹麻辣烫");
        shop.setAddress("东软食堂三期");
        shop.setPic(R.drawable.ic_launcher_background+"");
        shop.setLevel(3);
        list.add(shop);
        shop=new ShopBean();
        shop.setShopname("西湖印象");
        shop.setAddress("东软食堂二期");
        shop.setPic(R.drawable.ic_launcher_background+"");
        shop.setLevel(4);
        list.add(shop);
        shop=new ShopBean();
        shop.setShopname("丸子铺");
        shop.setAddress("东软食堂二期");
        shop.setPic(R.drawable.ic_launcher_background+"");
        shop.setLevel(2);
        list.add(shop);
        return list;
    }
    void initEvents()
    {
    }
}
